package com.guomao._22thymeleaf.controller;

import com.guomao._22thymeleaf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;

@Controller
public class ThymeleafController {

    @GetMapping("/hello")
    public String hello(Model model) {
        model.addAttribute("message", "Welcome to Thymeleaf!");
        model.addAttribute("name", "admin");


        model.addAttribute("element", "<h1>Hello Thymeleaf!</h1>");
        return "hello";
        // 对应 templates/hello.html
    }

    @GetMapping("/user")
    public String user(Model model) {
        User user = new User();
        user.setName("Alice");
        user.setAge(25);
        model.addAttribute("user", user);


        ArrayList<User> users = new ArrayList<>();
        users.add(user);
        users.add(user);
        users.add(user);

        model.addAttribute("users", users);

        return "user";
        // 对应 templates/user.html
    }
}